var mongoose=require('mongoose');
var config=require('../config');
var mongodb = require('mongodb');
var Schema=mongoose.Schema;
var db=mongoose.createConnection(config.db_url);
var _ = require("underscore");
db.on('error',function(error){
    db.close();
    console.log(error);
});

db.on('close', function () {
    db.open(config.db_url);
    console.log("重新连接mongo");
});

var billingSchema = new Schema({
    box_id: String,
    standard: Number, //基础时间
    price: Number,  //基础费用
    less: Number, //小于的时间
    lessprice: Number, //小于的费用
    more:Number, //大于的时间
    moreprice:Number //大于的费用
});
var Billing = db.model("Billing", billingSchema);

Billing.prototype.findSpriceById=function (boxid,callback){
    Billing.find({box_id:boxid}, function(err, datas){
        return callback(datas);
    });
}

Billing.prototype.removepriceById=function (boxid,callback){
    Billing.remove({box_id:boxid}, function(err){
        return callback(err);
    });
}

module.exports = Billing;